package com.yuma.function4;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

public class PredicateDemo {
    public static void main(String[] args) {
        Predicate<Integer> p1 = new Predicate<Integer>() {
            @Override
            public boolean test(Integer val) {
                return val % 2 == 0;
            }
        };
        System.out.println(p1.test(100));

        Predicate<String> p2 = val -> val.isEmpty();
        System.out.println(p2.test(""));

        List<String> list = new ArrayList<>();
        list.add("hello");
        list.add("kitty");
        list.add("yuma");
        list.add("function");
        //Predicate<? super T> T类对象以及T父类对象
        list.stream().filter(val -> val.length() > 5).forEach(val -> System.out.println(val));
        list.stream().filter(val -> val.contains("e")).forEach(val -> System.out.println(val));
        list.stream().filter(val -> !val.contains("e")).forEach(val -> System.out.println(val));
    }
}
